# The context stack is a private member of this module
# To access the current (top) context on the context stack: context.top()
# To push a new context onto the stack: context.push(con)
# To pop the top context off the stack: context.pop()

class Context(object):
    
    def think(self):
        """Called once per frame"""
        pass

    def resume(self):
        """Called when an already-existing context is again at the top of the stack"""
        pass

_cstack = list()

def top():
    return _cstack[-1] if _cstack else None

def push(con):
    if __debug__: print "context pushed: ", con.__class__.__name__
    _cstack.append(con)

def pop(n = 1):
    for j in range(n):
        if __debug__: print "context popping: ", _cstack[-1].__class__.__name__
        if _cstack: del _cstack[-1]
        if _cstack: _cstack[-1].resume()

